﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace Turnero.DAOs
{
    class BaseDatos
    {
        protected SqlTransaction tran;
        protected SqlConnection cn;

        protected SqlConnection ConectarDB()
        {
            //Cadena de conexion rober.
            //string cnstr = "Data Source=USERSIX-PC\\SQL2008R2;Initial Catalog=Turnero;Integrated Security=True";


            //Cadena de conexion horacles.

            //Cadena de conexion horacles notebook.
            //string cnstr = "Data Source=Horacles_Not;Initial Catalog=SisFacturacion_BD;Integrated Security=True";



            string cnstr = "Data Source=SERVER-PC;Initial Catalog=Turnero;Integrated Security=True";

            //string cnstr = "Data Source=Horacles_Not;Initial Catalog=SisFacturacion_BD;Integrated Security=True";



            //Cadena de conexion horacles server
            // string cnstr = "Data Source=server-pc;Initial Catalog=SisFacturacion_BD;Integrated Security=True";


            cn = new SqlConnection(cnstr);
            try
            {
                cn.Open();
            }
            catch (SqlException o)
            {
                cn.Dispose();
                Console.WriteLine(o.Message);
            }
            return cn;
        }

        protected void cerrarConexion()
        {
            cn.Close();
        }


        protected SqlTransaction crearTransaccion()
        {
            if (tran == null)
            {
                ConectarDB();
                tran = cn.BeginTransaction();
            }
            return tran;
        }
    }
}
